 
/**************************************************************************************************

        @file           variables.h
        @author         Jon Zeeff
        @date           December, 2011
        @brief          System variables that the tuner will read or write
        @copyright      MIT license
        @warning        needs more testing - send results to jon at zeeff.com
        @version        1.2
        
        @note 		parts of this are created from a TunerStudio .ini file with the program format_ini.c
        
****************************************************************************************************/

/* 

Copyright (c) 2011 Jon Zeeff

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#ifndef variables_h
#define variables_h

#include "etpu_util.h"
#include <stdint.h>
#include "Functions.h"

#ifndef EXTERN
#define EXTERN extern
#define NOINIT
#endif

// these are what the tuner uses
#define U08 uint8_t
#define S08 int8_t
#define U16 uint16_t
#define S16 int16_t

// subroutines related to this file
void init_variables(void);
void Set_Page_Locations(void);

//************************************************************************************

// below is manually mantained from the .ini file

#define   versionInfo    "S"  //  AKA title
#define version  "O5E 1.0.4 20111104                                         "
               //"12345678901234567890123456789012345678901234567890123456789"

#define   queryCommand   "Q"  // Verify against signature, revision number
// Change this every time you modify the .ini
#define   signature      "MShift 2.111       " // ; o5e sends a null at 20th byte.
//                       "123456789.123456789"

#define  nPages  	14
#define Max_Page_Size 2048

EXTERN const uint16_t pageSize[nPages]
#ifndef NOINIT
 = { 82,924,1520,1954,1672,1672,1672,1672,1952,1952,1952,1952,1952,1952 }
#endif
;

EXTERN const uint8_t  *pageIdentifier[nPages] 
#ifndef NOINIT
= {"\x00\x01", "\x00\x02", "\x00\x03", "\x00\x04", "\x00\x05", "\x00\x06", 
"\x00\x07","\x00\x08","\x00\x09","\x00\x0a", "\x00\x0b", "\x00\x0c", "\x00\x0d", "\x00\x0e" }
#endif
;

EXTERN const uint8_t *burnCommand[nPages]  
#ifndef NOINIT
= {"b\x00\x01", "b\x00\x02",  "b\x00\x03", "b\x00\x04", "b\x00\x05", "b\x00\x06", "b\x00\x07",
"b\x00\x08", "b\x00\x09",  "b\x00\x0a", "b\x00\x0b", "b\x00\x0c", "b\x00\x0d", "b\x00\x0e" }
#endif
;

EXTERN const uint8_t *pageReadCommand[nPages] 
#ifndef NOINIT
= {"r\x00\x01%2o%2c", "r\x00\x02%2o%2c", "r\x00\x03%2o%2c", "r\x00\x04%2o%2c",  "r\x00\x05%2o%2c",
"r\x00\x06%2o%2c", "r\x00\x07%2o%2c", "r\x00\x08%2o%2c", "r\x00\x09%2o%2c",  "r\x00\x0a%2o%2c",
"r\x00\x0b%2o%2c", "r\x00\x0c%2o%2c", "r\x00\x0d%2o%2c", "r\x00\x0e%2o%2c" }
#endif
;

EXTERN const uint8_t *pageValueWrite[nPages]  
#ifndef NOINIT
= {"w\x00\x01%2o%2c%v", "w\x00\x02%2o%2c%v", "w\x00\x03%2o%2c%v", "w\x00\x04%2o%2c%v", "w\x00\x05%2o%2c%v",
"w\x00\x06%2o%2c%v", "w\x00\x07%2o%2c%v", "w\x00\x08%2o%2c%v", "w\x00\x09%2o%2c%v", "w\x00\x0a%2o%2c%v",
"w\x00\x0b%2o%2c%v", "w\x00\x0c%2o%2c%v", "w\x00\x0d%2o%2c%v", "w\x00\x0e%2o%2c%v" }
#endif
;

EXTERN const uint8_t *pageChunkWrite[nPages] 
#ifndef NOINIT
= {"w\x00\x01%2o%2c%v", "w\x00\x02%2o%2c%v", "w\x00\x03%2o%2c%v", "w\x00\x04%2o%2c%v", "w\x00\x05%2o%2c%v",
"w\x00\x06%2o%2c%v", "w\x00\x07%2o%2c%v" ,"w\x00\x08%2o%2c%v", "w\x00\x09%2o%2c%v", "w\x00\x0a%2o%2c%v",
"w\x00\x0b%2o%2c%v", "w\x00\x0c%2o%2c%v", "w\x00\x0d%2o%2c%v", "w\x00\x0e%2o%2c%v" }
#endif
;

//*************************************

// All variables that may be sent to the tuner must be defined here and in the tuner.ini file with the exact same layout


// Output_Channels is special in that it is always in a fixed location in ram.  This allows us to define variables differently.
// Note, we trust that the compiler will keep these in order.
// This list is maintained manually and must match the .ini file exactly - same size, number and order

//[Output_Channels]
struct Outputs {

int16_t RPM;
int16_t RPM_Dot;
int16_t Load;
int16_t Load_Dot;
int16_t V_MAP[4];
int16_t V_Batt;
int16_t V_CLT;
int16_t V_IAT;
int16_t V_TPS;
int16_t V_MAF[2];
int16_t V_O2_UA[2];
int16_t V_O2_UR[2];
int16_t V_P[14];
int16_t TPS;
int16_t AFR[2];
int16_t MAP[4];
int16_t MAP_Dot[4];
int16_t MAF[2];
int16_t MAF_Dot[2];
int16_t CLT;
int16_t IAT;
int16_t Injection_Time;
int16_t Spark_Advance;
int16_t Inj_End_Angle;
int16_t Eng_Model_Corr;
uint16_t Post_Start_Time;
uint16_t Post_Start_Cycles;
uint16_t Post_Start_Cylinder;
uint32_t Last_Error;
int16_t Dwell;

};

// initialized to all zeros
EXTERN struct Outputs Output_Channels;

#define Output_Channels_Size  112        // this must match the structure above - don't use sizeof()

// these are for convenience and more readable code - must match above
#define RPM Output_Channels.RPM
#define RPM_Dot Output_Channels.RPM_Dot
#define Load Output_Channels.Load
#define Load_Dot Output_Channels.Load_Dot
#define V_MAP Output_Channels.V_MAP
#define V_Batt Output_Channels.V_Batt
#define V_CLT Output_Channels.V_CLT
#define V_IAT Output_Channels.V_IAT
#define V_TPS Output_Channels.V_TPS
#define V_MAF Output_Channels.V_MAF
#define V_O2 Output_Channels.V_O2
#define V_P Output_Channels.V_P
#define TPS Output_Channels.TPS
#define AFR Output_Channels.AFR
#define MAP Output_Channels.MAP
#define MAP_Dot Output_Channels.MAP_Dot
#define MAF Output_Channels.MAF
#define MAF_Dot Output_Channels.MAF_Dot
#define CLT Output_Channels.CLT
#define IAT Output_Channels.IAT
#define Injection_Time Output_Channels.Injection_Time
#define Spark_Advance Output_Channels.Spark_Advance
#define Inj_End_Angle Output_Channels.Inj_End_Angle
#define Eng_Model_Corr Output_Channels.Eng_Model_Corr
#define Post_Start_Time Output_Channels.Post_Start_Time
#define Post_Start_Cycles Output_Channels.Post_Start_Cycles
#define Post_Start_Cylinders Output_Channels.Post_Start_Cylinders
#define Last_Error Output_Channels.Last_Error
#define Dwell Output_Channels.Dwell

//*******************************************************

// allow writing to config variables for testing - see variables.c
#define CONST
//#define CONST const

// Flash Variables from .ini - auto generated, do not edit
//--------------------------------------------------------
#define N_Cyl (*(CONST U08 *)(&Page_Ptr[0][0]))
#define N_Teeth (*(CONST U08 *)(&Page_Ptr[0][1]))
#define Missing_Teeth (*(CONST U08 *)(&Page_Ptr[0][2]))
#define Cam_Lobe_Pos (*(CONST S16 *)(&Page_Ptr[0][4]))
#define Load_Sense (*(CONST U08 *)(&Page_Ptr[0][6]))
#define Cyl_Offset_1 (*(CONST S16 *)(&Page_Ptr[0][8]))
#define Cyl_Offset_Array ((CONST S16 *)(&Page_Ptr[0][8]))
#define Cyl_Offset_2 (*(CONST S16 *)(&Page_Ptr[0][10]))
#define Cyl_Offset_3 (*(CONST S16 *)(&Page_Ptr[0][12]))
#define Cyl_Offset_4 (*(CONST S16 *)(&Page_Ptr[0][14]))
#define Cyl_Offset_5 (*(CONST S16 *)(&Page_Ptr[0][16]))
#define Cyl_Offset_6 (*(CONST S16 *)(&Page_Ptr[0][18]))
#define Cyl_Offset_7 (*(CONST S16 *)(&Page_Ptr[0][20]))
#define Cyl_Offset_8 (*(CONST S16 *)(&Page_Ptr[0][22]))
#define Cyl_Offset_9 (*(CONST S16 *)(&Page_Ptr[0][24]))
#define Cyl_Offset_10 (*(CONST S16 *)(&Page_Ptr[0][26]))
#define Cyl_Offset_11 (*(CONST S16 *)(&Page_Ptr[0][28]))
#define Cyl_Offset_12 (*(CONST S16 *)(&Page_Ptr[0][30]))
#define Config_Ign_1 (*(CONST U08 *)(&Page_Ptr[0][32]))
#define Config_Ign_Array ((CONST U08 *)(&Page_Ptr[0][32]))
#define Config_Ign_2 (*(CONST U08 *)(&Page_Ptr[0][33]))
#define Config_Ign_3 (*(CONST U08 *)(&Page_Ptr[0][34]))
#define Config_Ign_4 (*(CONST U08 *)(&Page_Ptr[0][35]))
#define Config_Ign_5 (*(CONST U08 *)(&Page_Ptr[0][36]))
#define Config_Ign_6 (*(CONST U08 *)(&Page_Ptr[0][37]))
#define Config_Ign_7 (*(CONST U08 *)(&Page_Ptr[0][38]))
#define Config_Ign_8 (*(CONST U08 *)(&Page_Ptr[0][39]))
#define Config_Ign_9 (*(CONST U08 *)(&Page_Ptr[0][40]))
#define Config_Ign_10 (*(CONST U08 *)(&Page_Ptr[0][41]))
#define Config_Ign_11 (*(CONST U08 *)(&Page_Ptr[0][42]))
#define Config_Ign_12 (*(CONST U08 *)(&Page_Ptr[0][43]))
#define Config_Inj_1 (*(CONST U08 *)(&Page_Ptr[0][44]))
#define Config_Inj_Array ((CONST U08 *)(&Page_Ptr[0][44]))
#define Config_Inj_2 (*(CONST U08 *)(&Page_Ptr[0][45]))
#define Config_Inj_3 (*(CONST U08 *)(&Page_Ptr[0][46]))
#define Config_Inj_4 (*(CONST U08 *)(&Page_Ptr[0][47]))
#define Config_Inj_5 (*(CONST U08 *)(&Page_Ptr[0][48]))
#define Config_Inj_6 (*(CONST U08 *)(&Page_Ptr[0][49]))
#define Config_Inj_7 (*(CONST U08 *)(&Page_Ptr[0][50]))
#define Config_Inj_8 (*(CONST U08 *)(&Page_Ptr[0][51]))
#define Config_Inj_9 (*(CONST U08 *)(&Page_Ptr[0][52]))
#define Config_Inj_10 (*(CONST U08 *)(&Page_Ptr[0][53]))
#define Config_Inj_11 (*(CONST U08 *)(&Page_Ptr[0][54]))
#define Config_Inj_12 (*(CONST U08 *)(&Page_Ptr[0][55]))
#define Config_Inj_13 (*(CONST U08 *)(&Page_Ptr[0][56]))
#define Config_Inj_14 (*(CONST U08 *)(&Page_Ptr[0][57]))
#define Config_Inj_15 (*(CONST U08 *)(&Page_Ptr[0][58]))
#define Config_Inj_16 (*(CONST U08 *)(&Page_Ptr[0][59]))
#define Config_Inj_17 (*(CONST U08 *)(&Page_Ptr[0][60]))
#define Config_Inj_18 (*(CONST U08 *)(&Page_Ptr[0][61]))
#define Config_Inj_19 (*(CONST U08 *)(&Page_Ptr[0][62]))
#define Config_Inj_20 (*(CONST U08 *)(&Page_Ptr[0][63]))
#define Config_Inj_21 (*(CONST U08 *)(&Page_Ptr[0][64]))
#define Config_Inj_22 (*(CONST U08 *)(&Page_Ptr[0][65]))
#define Config_Inj_23 (*(CONST U08 *)(&Page_Ptr[0][66]))
#define Config_Inj_24 (*(CONST U08 *)(&Page_Ptr[0][67]))
#define Config_LS_1 (*(CONST U08 *)(&Page_Ptr[0][68]))
#define Config_LS_Array ((CONST U08 *)(&Page_Ptr[0][68]))
#define Config_LS_2 (*(CONST U08 *)(&Page_Ptr[0][69]))
#define Config_LS_3 (*(CONST U08 *)(&Page_Ptr[0][70]))
#define Config_LS_4 (*(CONST U08 *)(&Page_Ptr[0][71]))
#define Config_LS_5 (*(CONST U08 *)(&Page_Ptr[0][72]))
#define Config_LS_6 (*(CONST U08 *)(&Page_Ptr[0][73]))
#define Config_HS_1 (*(CONST U08 *)(&Page_Ptr[0][74]))
#define Config_HS_Array ((CONST U08 *)(&Page_Ptr[0][74]))
#define Config_HS_2 (*(CONST U08 *)(&Page_Ptr[0][75]))
#define Config_HS_3 (*(CONST U08 *)(&Page_Ptr[0][76]))
#define Config_HS_4 (*(CONST U08 *)(&Page_Ptr[0][77]))
#define Config_Stepper (*(CONST U08 *)(&Page_Ptr[0][78]))
#define Engine_Position (*(CONST S16 *)(&Page_Ptr[0][80]))
#define Drop_Dead_Angle (*(CONST S16 *)(&Page_Ptr[0][82]))
#define Ignition_Type (*(CONST U08 *)(&Page_Ptr[0][84]))
#define Fuel_Temp_Corr_Table ((CONST struct table_jz *)(&Page_Ptr[1][0]))
#define IAT_Fuel_Corr_Table ((CONST struct table_jz *)(&Page_Ptr[1][168]))
#define Inj_Dead_1 (*(CONST S16 *)(&Page_Ptr[1][336]))
#define Inj_Dead_Array ((CONST S16 *)(&Page_Ptr[1][336]))
#define Inj_Dead_2 (*(CONST S16 *)(&Page_Ptr[1][338]))
#define Inj_Dead_3 (*(CONST S16 *)(&Page_Ptr[1][340]))
#define Inj_Dead_4 (*(CONST S16 *)(&Page_Ptr[1][342]))
#define Inj_Dead_5 (*(CONST S16 *)(&Page_Ptr[1][344]))
#define Inj_Dead_6 (*(CONST S16 *)(&Page_Ptr[1][346]))
#define Inj_Dead_7 (*(CONST S16 *)(&Page_Ptr[1][348]))
#define Inj_Dead_8 (*(CONST S16 *)(&Page_Ptr[1][350]))
#define Inj_Dead_9 (*(CONST S16 *)(&Page_Ptr[1][352]))
#define Inj_Dead_10 (*(CONST S16 *)(&Page_Ptr[1][354]))
#define Inj_Dead_11 (*(CONST S16 *)(&Page_Ptr[1][356]))
#define Inj_Dead_12 (*(CONST S16 *)(&Page_Ptr[1][358]))
#define Inj_Dead_13 (*(CONST S16 *)(&Page_Ptr[1][360]))
#define Inj_Dead_14 (*(CONST S16 *)(&Page_Ptr[1][362]))
#define Inj_Dead_15 (*(CONST S16 *)(&Page_Ptr[1][364]))
#define Inj_Dead_16 (*(CONST S16 *)(&Page_Ptr[1][366]))
#define Inj_Dead_17 (*(CONST S16 *)(&Page_Ptr[1][368]))
#define Inj_Dead_18 (*(CONST S16 *)(&Page_Ptr[1][370]))
#define Inj_Dead_19 (*(CONST S16 *)(&Page_Ptr[1][372]))
#define Inj_Dead_20 (*(CONST S16 *)(&Page_Ptr[1][374]))
#define Inj_Dead_21 (*(CONST S16 *)(&Page_Ptr[1][376]))
#define Inj_Dead_22 (*(CONST S16 *)(&Page_Ptr[1][378]))
#define Inj_Dead_23 (*(CONST S16 *)(&Page_Ptr[1][380]))
#define Inj_Dead_24 (*(CONST S16 *)(&Page_Ptr[1][382]))
#define Enable_Ignition (*(CONST U08 *)(&Page_Ptr[1][384]))
#define Enable_Map_Control (*(CONST U08 *)(&Page_Ptr[1][385]))
#define Enable_Inj (*(CONST U08 *)(&Page_Ptr[1][386]))
#define Dwell_Table ((CONST struct table_jz *)(&Page_Ptr[1][388]))
#define Dwell_Set (*(CONST S16 *)(&Page_Ptr[1][540]))
#define Dead_Time_Set (*(CONST S16 *)(&Page_Ptr[1][542]))
#define Rev_Limit (*(CONST S16 *)(&Page_Ptr[1][544]))
#define Soft_Rev_Limit (*(CONST S16 *)(&Page_Ptr[1][546]))
#define Rev_Limit_Type (*(CONST U08 *)(&Page_Ptr[1][548]))
#define Max_Inj_Time (*(CONST S16 *)(&Page_Ptr[1][550]))
#define Inj_Dead_Time_Table ((CONST struct table_jz *)(&Page_Ptr[1][552]))
#define Eng_Model_Table ((CONST struct table_jz *)(&Page_Ptr[1][704]))
#define Staged_Inj (*(CONST U08 *)(&Page_Ptr[1][904]))
#define Stage_Load (*(CONST U08 *)(&Page_Ptr[1][905]))
#define staged_Load_Dead (*(CONST U08 *)(&Page_Ptr[1][906]))
#define Stage_RPM (*(CONST S16 *)(&Page_Ptr[1][908]))
#define Staged_RPM_Dead (*(CONST S16 *)(&Page_Ptr[1][910]))
#define Enable_Accel_Decel (*(CONST U08 *)(&Page_Ptr[1][912]))
#define IAC_Enable (*(CONST U08 *)(&Page_Ptr[1][913]))
#define Warm_Idle_RPM (*(CONST S16 *)(&Page_Ptr[1][914]))
#define Cold_Idle_RPM (*(CONST S16 *)(&Page_Ptr[1][916]))
#define Warm_Start_IAC (*(CONST U08 *)(&Page_Ptr[1][918]))
#define Cold_start_IAC (*(CONST U08 *)(&Page_Ptr[1][919]))
#define Warm_IAC (*(CONST U08 *)(&Page_Ptr[1][920]))
#define Cold_IAC (*(CONST U08 *)(&Page_Ptr[1][921]))
#define Warm_Idle_Temp (*(CONST S16 *)(&Page_Ptr[1][922]))
#define Warm_Start_Temp (*(CONST S16 *)(&Page_Ptr[1][924]))
#define MAP_Angle_Table ((CONST struct table_jz *)(&Page_Ptr[2][926]))
#define Dwell_Min (*(CONST U08 *)(&Page_Ptr[2][1126]))
#define Dwell_Max (*(CONST U08 *)(&Page_Ptr[2][1127]))
#define Wetting_Temp_Corr_Table ((CONST struct table_jz *)(&Page_Ptr[3][0]))
#define Manifold_Wetting_Table ((CONST struct table_jz *)(&Page_Ptr[3][648]))
#define Max_Enrich_Table ((CONST struct table_jz *)(&Page_Ptr[3][848]))
#define Accel_Step_Table ((CONST struct table_jz *)(&Page_Ptr[3][1016]))
#define Max_Derich_Table ((CONST struct table_jz *)(&Page_Ptr[3][1184]))
#define Decel_Step_Table ((CONST struct table_jz *)(&Page_Ptr[3][1352]))
#define CLT_Table ((CONST struct table_jz *)(&Page_Ptr[4][0]))
#define CLT_Cal_Array ((CONST S16 *)(&Page_Ptr[4][136]))
#define IAT_Table ((CONST struct table_jz *)(&Page_Ptr[4][168]))
#define IAT_Cal_Array ((CONST S16 *)(&Page_Ptr[4][304]))
#define TPS_Table ((CONST struct table_jz *)(&Page_Ptr[4][336]))
#define TPS_Flow_Cal_On (*(CONST U08 *)(&Page_Ptr[4][474]))
#define TPS_Flow_Table ((CONST struct table_jz *)(&Page_Ptr[4][476]))
#define AFR_1_Table ((CONST struct table_jz *)(&Page_Ptr[4][644]))
#define AFR_2_Table ((CONST struct table_jz *)(&Page_Ptr[4][812]))
#define MAF_1_Table ((CONST struct table_jz *)(&Page_Ptr[4][874]))
#define MAF_1_Cal_Array ((CONST S16 *)(&Page_Ptr[4][1010]))
#define MAF_2_Table ((CONST struct table_jz *)(&Page_Ptr[4][1042]))
#define MAF_2_Cal_Array ((CONST S16 *)(&Page_Ptr[4][1178]))
#define MAP_1_Table ((CONST struct table_jz *)(&Page_Ptr[4][1210]))
#define MAP_1_Cal_Array ((CONST S16 *)(&Page_Ptr[4][1346]))
#define MAP_2_Table ((CONST struct table_jz *)(&Page_Ptr[4][1378]))
#define MAP_2_Cal_Array ((CONST S16 *)(&Page_Ptr[4][1514]))
#define MAP_3_Table ((CONST struct table_jz *)(&Page_Ptr[4][1546]))
#define MAP_3_Cal_Array ((CONST S16 *)(&Page_Ptr[4][1678]))
#define MAP_4_Table ((CONST struct table_jz *)(&Page_Ptr[4][1710]))
#define MAP_4_Cal_Array ((CONST S16 *)(&Page_Ptr[4][1846]))
#define Man_Crank_Corr_Table ((CONST struct table_jz *)(&Page_Ptr[4][1878]))
#define Inj_Time_Corr_Table ((CONST struct table_jz *)(&Page_Ptr[5][0]))
#define Inj_End_Angle_Table ((CONST struct table_jz *)(&Page_Ptr[5][0]))
#define Spark_Advance_Table ((CONST struct table_jz *)(&Page_Ptr[5][0]))
#define AFR_Set_Point_Table ((CONST struct table_jz *)(&Page_Ptr[5][0]))
#define Cyl_Trim_1_Table ((CONST struct table_jz *)(&Page_Ptr[5][0]))
#define Cyl_Trim_2_Table ((CONST struct table_jz *)(&Page_Ptr[5][488]))
#define Cyl_Trim_3_Table ((CONST struct table_jz *)(&Page_Ptr[5][976]))
#define Cyl_Trim_4_Table ((CONST struct table_jz *)(&Page_Ptr[5][1464]))
#define Cyl_Trim_5_Table ((CONST struct table_jz *)(&Page_Ptr[6][0]))
#define Cyl_Trim_6_Table ((CONST struct table_jz *)(&Page_Ptr[6][488]))
#define Cyl_Trim_7_Table ((CONST struct table_jz *)(&Page_Ptr[6][976]))
#define Cyl_Trim_8_Table ((CONST struct table_jz *)(&Page_Ptr[6][1464]))
#define Cyl_Trim_9_Table ((CONST struct table_jz *)(&Page_Ptr[7][0]))
#define Cyl_Trim_10_Table ((CONST struct table_jz *)(&Page_Ptr[7][488]))
#define Cyl_Trim_11_Table ((CONST struct table_jz *)(&Page_Ptr[7][976]))
#define Cyl_Trim_12_Table ((CONST struct table_jz *)(&Page_Ptr[7][1464]))
#define Coil_Trim_1_Table ((CONST struct table_jz *)(&Page_Ptr[8][0]))
#define Coil_Trim_2_Table ((CONST struct table_jz *)(&Page_Ptr[8][488]))
#define Coil_Trim_3_Table ((CONST struct table_jz *)(&Page_Ptr[8][976]))
#define Coil_Trim_4_Table ((CONST struct table_jz *)(&Page_Ptr[8][1464]))
#define Coil_Trim_5_Table ((CONST struct table_jz *)(&Page_Ptr[9][0]))
#define Coil_Trim_6_Table ((CONST struct table_jz *)(&Page_Ptr[9][488]))
#define Coil_Trim_7_Table ((CONST struct table_jz *)(&Page_Ptr[9][976]))
#define Coil_Trim_8_Table ((CONST struct table_jz *)(&Page_Ptr[9][1464]))
#define Coil_Trim_9_Table ((CONST struct table_jz *)(&Page_Ptr[10][0]))
#define Coil_Trim_10_Table ((CONST struct table_jz *)(&Page_Ptr[10][488]))
#define Coil_Trim_11_Table ((CONST struct table_jz *)(&Page_Ptr[10][976]))
#define Coil_Trim_12_Table ((CONST struct table_jz *)(&Page_Ptr[10][1464]))
// ------------------------------------------------------------------------
// Below here does not come from the .ini file

// Variables not in .ini
EXTERN uint8_t Error_String[100];

// Current flash or ram location of each page
EXTERN uint8_t *Page_Ptr[nPages];
// Ram buffer to store a single page before writing to flash
EXTERN uint8_t Ram_Page_Buffer[Max_Page_Size];

#define Flash_Base 0x40000      // memory address of fist flash block
EXTERN uint8_t Flash_Block;		// flash block currently being used - 0=M0 or 1=H0 block
EXTERN uint8_t Flash_Moved[nPages];        // set to 1 if page has been written to new flash block
EXTERN uint8_t *Flash_Addr[2] 
#ifndef NOINIT
 = { (uint8_t *)0x40000, (uint8_t *)0x80000 }      // memory address of flash blocks (M0, H0)
#endif
;

#endif

#undef EXTERN
#undef NOINIT




